//package com.sharding.jdbc.config;
//
//import com.alibaba.druid.pool.DruidDataSource;
//import org.apache.shardingsphere.core.rule.ShardingRule;
//import org.apache.shardingsphere.shardingjdbc.jdbc.core.datasource.ShardingDataSource;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.yaml.snakeyaml.Yaml;
//
//import javax.sql.DataSource;
//import java.io.UnsupportedEncodingException;
//import java.sql.SQLException;
//import java.util.HashMap;
//import java.util.Map;
//
///**
// * 描述
// *
// * @author zhu_jinsheng
// * @version 1.0
// * @date 2020/8/27 14:10
// */
//
//@Configuration
//public class SpringConfig {
//    @Bean("shardingDataSource")
//    public ShardingDataSource createProductBean(DruidDataSource x_ds_0, DruidDataSource x_ds_1,
//                                                DruidDataSource x_ds_2, DruidDataSource x_ds_3,
//                                                DruidDataSource x_ds_4, DruidDataSource x_ds_5,
//                                                DruidDataSource x_ds_6, DruidDataSource x_ds_7,
//                                                DruidDataSource x_ds_8) throws SQLException {
//
//        Map<String, DataSource> dataSourceMap = new HashMap<>();
//        dataSourceMap.put("x_ds_0", x_ds_0);
//        dataSourceMap.put("x_ds_1", x_ds_1);
//        dataSourceMap.put("x_ds_2", x_ds_2);
//        dataSourceMap.put("x_ds_3", x_ds_3);
//        dataSourceMap.put("x_ds_4", x_ds_4);
//        dataSourceMap.put("x_ds_5", x_ds_5);
//        dataSourceMap.put("x_ds_6", x_ds_6);
//        dataSourceMap.put("x_ds_7", x_ds_7);
//        dataSourceMap.put("x_ds_8", x_ds_8);
//
//        YamlShardingConfiguration yamlShardingConfiguration = getYamlShardingConfiguration();
//        ShardingRule shardingRule = yamlShardingConfiguration.getShardingRule().getShardingRuleConfiguration().build(dataSourceMap);
//        return new ShardingDataSource(shardingRule);
//
//    }
//
//    public static YamlShardingConfiguration getYamlShardingConfiguration() {
//        YamlShardingConfiguration yamlShardingConfiguration = null;
//        try (
//                InputStream fileInputStream = SpringConfig.class.getResource("/yarmdb.yaml").openStream();
//                InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream, "UTF-8")
//        ) {
//            yamlShardingConfiguration = new Yaml(new Constructor(YamlShardingConfiguration.class)).loadAs(inputStreamReader, YamlShardingConfiguration.class);
//        } catch (UnsupportedEncodingException e) {
//            e.printStackTrace();
//        } catch (FileNotFoundException e) {
//            e.printStackTrace();
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//        return yamlShardingConfiguration;
//    }
//}